package com.example.as_sum.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;

import com.example.as_sum.activity.BaseActivity;
import com.example.as_sum.activity.HttpActivity;
import com.example.as_sum.activity.LoginActivity;
import com.example.as_sum.activity.MsgInfoActivity;
import com.example.as_sum.activity.NewLayoutActivity;
import com.example.as_sum.activity.PermissionActivity;
import com.example.as_sum.activity.PersonInfoActivity;
import com.example.as_sum.activity.SafetyCenterActivity;
import com.example.as_sum.activity.SettingActivity;
import com.example.as_sum.activity.TestActivity;
import com.example.as_sum.application.AppApplication;
import com.example.as_sum.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.example.as_sum.R;
import com.example.as_sum.util.SharePerferenceUtil;
import com.example.as_sum.util.StatusBarCompat;

/**
 * Created by ran on 2016/7/15.
 */
public class MainLeftFragment extends BaseFragment implements View.OnClickListener{
    private BaseActivity bContext;
    private ImageView img;
    private RelativeLayout layout_msg,layout_setting,layout_safety,
            layout_network,layout_test,layout_permission,layout_new;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragmen_main_left,container,false);
    }
    @Override
    public void initView(View view) {
        StatusBarCompat.setStatusBarColor(bContext,getResources().getColor(R.color.colorPrimary));
        img = (ImageView) view.findViewById(R.id.main_left_img_persion);
        layout_msg = (RelativeLayout) view.findViewById(R.id.slide_layout_msg);
        layout_safety = (RelativeLayout) view.findViewById(R.id.slide_layout_safety);
        layout_setting = (RelativeLayout) view.findViewById(R.id.slide_layout_setting);
        layout_network = (RelativeLayout) view.findViewById(R.id.slide_layout_network);
        layout_test = (RelativeLayout) view.findViewById(R.id.slide_layout_test);
        layout_permission = (RelativeLayout) view.findViewById(R.id.slide_layout_permission);
        layout_new = (RelativeLayout) view.findViewById(R.id.slide_layout_new);
    }

    @Override
    public void addListener() {
        img.setOnClickListener(this);
        layout_msg.setOnClickListener(this);
        layout_safety.setOnClickListener(this);
        layout_setting.setOnClickListener(this);
        layout_network.setOnClickListener(this);
        layout_test.setOnClickListener(this);
        layout_permission.setOnClickListener(this);
        layout_new.setOnClickListener(this);
    }

    @Override
    public void setParam() {

    }

    @Override
    public Handler getUIHandler() {
        return null;
    }

    @Override
    protected void loadUIData() {

    }
    @Override
    public void onClick(View v) {
        if(SharePerferenceUtil.getMobile(getActivity()).equals("")){
            //还没登陆
            AppApplication.aContext.gotoLogin(bContext,false);
            return;
        }
        Intent intent=new Intent();
        switch (v.getId()){
            case R.id.main_left_img_persion:
                intent.setClass(bContext, PersonInfoActivity.class);
                startActivity(intent);
                break;
            case R.id.slide_layout_msg:
                intent.setClass(bContext, MsgInfoActivity.class);
                startActivity(intent);
                break;
            case R.id.slide_layout_setting:
                intent.setClass(bContext, SettingActivity.class);
                startActivity(intent);
                break;
            case R.id.slide_layout_safety:
                intent.setClass(bContext, SafetyCenterActivity.class);
                startActivity(intent);
                break;
            case R.id.slide_layout_network:
                intent.setClass(bContext, HttpActivity.class);
                startActivity(intent);
                break;
            case R.id.slide_layout_test:
                intent.setClass(bContext, TestActivity.class);
                startActivity(intent);
                break;
            case R.id.slide_layout_permission:
                intent.setClass(bContext, PermissionActivity.class);
                startActivity(intent);
                break;
            case R.id.slide_layout_new:
                intent.setClass(bContext, NewLayoutActivity.class);
                startActivity(intent);
                break;
        }
    }
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        bContext=(BaseActivity)activity;
        //这个Activity就是创建Fragment的Activity对象
        Log.e("侧滑Fragment","onAttach");
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.e("侧滑Fragment", "onCreate");
    }

    @Override
    public void fetchData() {

    }

    @Override
    public void onStart() {
        super.onStart();
        Log.e("侧滑Fragment", "onStart");
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.e("侧滑Fragment", "onResume");
    }

    @Override
    public void onPause() {
        super.onPause();
        Log.e("侧滑Fragment", "onPause");
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.e("侧滑Fragment", "onStop");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.e("侧滑Fragment", "onDestroy");
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.e("侧滑Fragment", "onDestroyView");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        Log.e("侧滑Fragment", "onDetach");
    }
}
